<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录页面</title>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>

<body>
    <!-- 登录表单 -->
    <form id="form1">
        <div>账号：<input type="text" name="username" autocomplete="off" /></div>
        <div>密码：<input type="password" name="password" /></div>
        <button>登录</button>
    </form>

    <script>
        const form = document.getElementById('form1')
        form.onsubmit = (e) => {
            e.preventDefault()
            let data = {
                username: form.username.value,
                password: form.password.value
            }
            axios({
                url: 'http://127.0.0.1/api/login',
                method: 'POST',
                data,
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded'
                }
            }).then(function (res) {
                if (res.data.status === 0) {
                    location.href = './home.html'
                } else {
                    alert('登录失败！')
                }
            });
        }
    </script>
</body>

</html>